<?php
define('IN_FLYWHEEL', true);

define('_DS_', DIRECTORY_SEPARATOR);
define('_ROOT_PATH_', dirname(__FILE__)._DS_);
define('_VENDORS_PATH_', _ROOT_PATH_.'vendors'._DS_);
define('_PROJECT_CONFIGURATION_PATH_', _ROOT_PATH_.'config'._DS_);
define('_SYSTEMS_PATH_', _ROOT_PATH_.'systems'._DS_);

//Auto load core class
require_once _SYSTEMS_PATH_.'autoload'._DS_.'fSystemAutoload.class.php';
fSystemAutoload::register();

require_once _VENDORS_PATH_.'doctrine'._DS_.'Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine', 'modelsAutoload'));	
require_once _SYSTEMS_PATH_.'databases'._DS_.'fDatabase.class.php';
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
$manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_NONE);
$manager->setAttribute(Doctrine::ATTR_RECURSIVE_MERGE_FIXTURES, true);
$manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
$manager->setDefaultAttributes();

Doctrine::loadModels(dirname(__FILE__) . _DS_ . 'models');

fDatabase::getConnection();
// Configure Doctrine Cli
// Normally these are arguments to the cli tasks but if they are set here the arguments will be auto-filled
$config = array('data_fixtures_path'  =>  dirname(__FILE__) . _DS_ . 'database'._DS_.'fixtures',
                'models_path'         =>  dirname(__FILE__) . _DS_ . 'models',
                'migrations_path'     =>  dirname(__FILE__) . _DS_ . 'database'._DS_.'migrations',
                'sql_path'            =>  dirname(__FILE__) . _DS_ . 'database'._DS_.'sql',
                'yaml_schema_path'    =>  dirname(__FILE__) . _DS_ . 'database');

$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);